﻿@using BTTechnologies.MedScience.MVC.Helpers
@using BTTechnologies.MedScience.MVC.Infrastructure.Security
@model BTTechnologies.MedScience.MVC.Models.AddEditAuthorModel
@{
    ViewBag.Title = MedSiteStrings.EditingAuthorTitle;
    
    bool canEditLinkedAccount = ServicesHelper.GetMembershipService().UserHasPrivilege(HttpContext.Current.User.Identity.Name, Privilege.EditAuthorAccountPrivilege);
}

<hgroup class="title">
    <h1>@MedSiteStrings.EditingAuthorTitle</h1>
    
    @Html.Partial("_OkErrorHeaderPartial", Model)
</hgroup>

<section id="centeredForm">
    @using (Html.BeginForm("AddEditAuthor", "Author"))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>
            <legend>@MedSiteStrings.EditingAuthorFormTitle</legend>
            <input type="hidden" name="Id" id="Id" value="@Model.Id" />
            @Html.HiddenFor(m => m.AccountId)

            <ol>
                <li>
                    @Html.LabelFor(m => m.Surname)
                    @Html.ValidationMessageFor(m => m.Surname)
                    @Html.TextBoxFor(m => m.Surname)
                </li>
                <li>
                    @Html.LabelFor(m => m.Name)
                    @Html.ValidationMessageFor(m => m.Name)
                    @Html.TextBoxFor(m => m.Name)
                </li>
                <li>
                    @Html.LabelFor(m => m.Patronymic)
                    @Html.ValidationMessageFor(m => m.Patronymic)
                    @Html.TextBoxFor(m => m.Patronymic)
                </li>
                <li>
                    @Html.LabelFor(m => m.EMail)
                    @Html.ValidationMessageFor(m => m.EMail)
                    @Html.TextBoxFor(m => m.EMail)
                </li>
                <li>
                    @Html.LabelFor(m => m.Phone)
                    @Html.ValidationMessageFor(m => m.Phone)
                    @Html.TextBoxFor(m => m.Phone)
                </li>
                <li>
                    @Html.LabelFor(m => m.Degree)
                    @Html.ValidationMessageFor(m => m.Degree)
                    @Html.TextAreaFor(m => m.Degree)
                </li>
                
                @if (canEditLinkedAccount)
                {
                    <li>
                        @Html.LabelFor(m => m.AccountName) 
                        <div id="DropDownWithFieldDiv">
                            <table style="margin: 10px auto 10px auto;" class="styledTable">
                                <tr>
                                    <td>
                                        <ul class="dropdown">
                                            <li>
                                                <div href="#">@MedSiteStrings.SelectAuthorsAccount</div>
                                                <ul class="sub_menu">
                                                    <li>
                                                        <div onclick="SelectAccountById(null, '@MedSiteStrings.NoAccount')">@MedSiteStrings.NoAccount</div>
                                                    </li>    

                                                    @foreach (KeyValuePair<int, string> pair in Model.AccountIdsAndNames)
                                                    {
                                                        <li>
                                                            <div onclick="SelectAccountById(@pair.Key, '@pair.Value')">@pair.Value</div>
                                                        </li>
                                                    }
                                                </ul>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="text" readonly="readonly" name="AccountName" id="AccountName" disabled="disabled" class="readonly" value="@Model.AccountName" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </li>
                    <li>
                        @Html.CheckBoxFor(m => m.AuthorStatus)
                        @Html.LabelFor(m => m.AuthorStatus, new {@class = "checkbox"})
                    </li>
                }
            </ol>            
            <input type="submit" value="@MedSiteStrings.Save" />
        </fieldset>
    }
</section>

@section scripts {
    @Scripts.Render("~/bundles/DropDown")
    @Scripts.Render("~/bundles/EditAuthorByAdmin")
}